<template>
  <!--
          作者：zy
          时间：2021-03-20
          描述：车辆-车辆列表
      -->
  <div class="user">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="司机名称"><el-input v-model="formInline.realname" placeholder="请输入司机名称"></el-input></el-form-item>

        <el-form-item label="审核状态">
          <el-select v-model="formInline.status" placeholder="请选择">
            <el-option label="全部" value=""></el-option>
            <el-option  label="未审核" value="0"></el-option>
            <el-option  label="审核通过" value="1"></el-option>
            <el-option  label="审核驳回" value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="添加时间">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker v-model="formInline.reg_date" type="daterange"  value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </div>
        </el-form-item>
        <el-form-item><el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button></el-form-item>
      </el-form>
    </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
          <el-table-column prop="driver_id" label="ID" width="80"></el-table-column>
          <el-table-column prop="realname" label="姓名"></el-table-column>
          <el-table-column prop="mobile" label="手机号"></el-table-column>
          <el-table-column label="性别">
            <template slot-scope="scope">
              <span v-if="scope.row.sex == 1" >男</span>
              <span v-if="scope.row.sex == 2" >女</span>
            </template>
          </el-table-column>
          <el-table-column prop="pay" label="报酬"></el-table-column>
          <el-table-column prop="age_name" label="驾龄"></el-table-column>
          <el-table-column prop="type_name" label="驾照类型"></el-table-column>
          <el-table-column label="状态" width="80">
            <template slot-scope="scope">
              <span v-if="scope.row.status == 0" class="red">未审核</span>
              <span v-if="scope.row.status == 1" class="green">审核通过</span>
              <span v-if="scope.row.status == 2" class="gray">已驳回</span>
            </template>
          </el-table-column>
          <el-table-column prop="create_time" label="添加时间" width="140"></el-table-column>

          <el-table-column fixed="right" label="操作" width="160">
            <template slot-scope="scope">
              <el-button @click="detailsClick(scope.row)" type="text" size="small" v-if="scope.row.status==0"  v-auth="'/driver/detail'">审核</el-button>
              <el-button @click="detailsClick(scope.row)" type="text" size="small" v-if="scope.row.status>0"  v-auth="'/driver/detail'">查看</el-button>
              <el-button @click="deleteClick(scope.row)" type="text" size="small" v-auth="'/driver/delete'">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        ></el-pagination>
      </div>
    </div>

    <!--会员充值-->
    <Recharge v-if="open_add" :open_add="open_add" :form="userModel" :gradeList="gradeList" @closeDialog="closeDialogFunc($event, 'add')"></Recharge>

    <!--会员等级-->
    <Grade v-if="open_edit" :open_edit="open_edit" :form="userModel" :gradeList="gradeList" @closeDialog="closeDialogFunc($event, 'edit')"></Grade>
  </div>
</template>

<script>
import UserApi from '@/api/user.js';
import CarApi from '@/api/car.js';
export default {

  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 15,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        realname: '',
        status:''
      },
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      userModel: {},
      /*等级*/
      gradeList: []
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },

    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = self.formInline;
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      CarApi.driverlist(Params, true)
        .then(data => {
          self.loading = false;
          self.tableData = data.data.list.data;
          self.totalDataNumber = data.data.list.total;
          self.gradeList = data.data.grade;
        })
        .catch(error => {
          self.loading = false;
        });
    },

    /*搜索查询*/
    onSubmit() {
      let self = this;
      self.curPage = 1;
      self.loading = true;
      let Params = self.formInline;
      self.getTableList();
    },

    /*打开添加*/
    addClick(item) {
      this.userModel = item;
      this.open_add = true;
    },

    /*打开编辑*/
    editClick(item) {
      this.userModel = item;
      this.open_edit = true;
    },

    /*关闭弹窗*/
    closeDialogFunc(e, f) {
      if (f == 'add') {
        this.open_add = e.openDialog;
        if (e.type == 'success') {
          this.getTableList();
        }
      }
      if (f == 'edit') {
        this.open_edit = e.openDialog;
        if (e.type == 'success') {
          this.getTableList();
        }
      }
    },
    /*打开编辑*/
    detailsClick(row) {
      let self = this;
      let params = row.driver_id;
      this.$router.push({
        path: '/driver/detail',
        query: {
          id: params
        }
      })
    },
    /*删除用户*/
    deleteClick(row) {
      let self = this;
      self
        .$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          self.loading = true;
          CarApi.deleteDriver(
            {
              id: row.driver_id
            },
            true
          )
            .then(data => {
              self.loading = false;
              if (data.code == 1) {
                self.$message({
                  message: '恭喜你，删除成功',
                  type: 'success'
                });
                self.getTableList();
              } else {
                self.loading = false;
              }
            })
            .catch(error => {
              self.loading = false;
            });
        })
        .catch(() => {
          self.loading = false;
        });
    }
  }
};
</script>
<style></style>
